﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Logging;

using Microsoft.Cci;
using PartialExpressionCompleter.Query;

namespace PartialExpressionCompleter.Experiment
{
    abstract class MethodExperiment : ExpressionExperiment<IMethodCall>
    {
        public MethodExperiment(IAssembly unit)
            : base(unit)
        { }

        protected abstract void DoMethodCallAction(QueryContext<IMethodCall> context);
        protected override void DoExpressionAction(QueryContext<IMethodCall> context)
        {
            DoMethodCallAction(context);
        }
        protected override IEnumerable<SavedExpression<IMethodCall>> GetAllSavedExpressions(AbstractTypeInferencer inferencer)
        {
            return inferencer.GetAllCalls();
        }
        protected override bool IsInterestingExpression(IMethodCall call)
        {
             var c = call;
             return (!(c.MethodToCall.ResolvedMethod is Dummy
                    || c.MethodToCall.ResolvedMethod.IsConstructor
                    || c.MethodToCall.ResolvedMethod.IsStaticConstructor)
                    && ((c.IsStaticCall && c.Arguments.Count() > 2)
                        || c.Arguments.Count() > 1)
                    && !c.MethodToCall.Name.ToString().StartsWith("op_")
                    && !c.MethodToCall.Name.ToString().StartsWith("set_")
                    && !c.MethodToCall.Name.ToString().StartsWith("get_")
                    && !c.MethodToCall.Name.ToString().Equals("CompareExchange"));
        }
    }
}
